﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using System.IO;
using DigiLib;

public partial class Administrator_Controls_HomeLinkAdd : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string name = txtName.Text.Trim();
            string link = txtLink.Text.Trim();
            string filename = base.Upload("homelink", string.Empty, fupThumb, divMessage, false);
            int order = Convert.ToInt32(txtOrder.Text.Trim());
            DataSet objDS = new DataSet();
            objDS.ReadXml(Server.MapPath("~/slide.xml"));
            ObjDT = objDS.Tables[0];
            DataRow drow = ObjDT.NewRow();
            drow["title"] = name;
            drow["link"] = link;
            drow["image"] = filename;
            if (order > ObjDT.Rows.Count)
                order = ObjDT.Rows.Count;
            else if (order < 0)
                order = 0;
            ObjDT.Rows.InsertAt(drow, order);
            objDS.WriteXml(Server.MapPath("~/slide.xml"));
            divMessage.InnerHtml = MessageBox.Success("Hệ Thống", "Thêm mới menu hệ thống thành công!");
            base.Clear(this.Controls);
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
}
